package com.dotstone.chipism.adapter;

import java.util.List;

import com.dotstone.chipism.R;
import com.tiqiaa.remote.entity.Brand;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BrandAdapter extends BaseAdapter {

	private Context context;
	private List<Brand> data;
	private Handler mHandler;

	public BrandAdapter(Context context) {
		this.context = context;
	}

	public BrandAdapter(Context context, List<Brand> data) {
		this.data = data;
		this.context = context;
	}

	public void setData(List<Brand> data) {
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void clear() {
		this.data.clear();
		notifyDataSetChanged();
	}

	public void addAll(List<Brand> data) {
		if (data != null) {
			this.data.addAll(data);
			notifyDataSetChanged();
		}
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.item_brand, null);
			holdView = new HoldView();
			holdView.cnTv = (TextView) view.findViewById(R.id.name_cn);
			holdView.enTv = (TextView) view.findViewById(R.id.name_en);
			view.setTag(holdView);
		} else {
			holdView = (HoldView) view.getTag();
		}
		Brand b = data.get(position);
		holdView.cnTv.setText(b.getBrand_cn());
		holdView.enTv.setText(b.getBrand_en());
		
		return view;
	}

	HoldView holdView;

	class HoldView {
		private TextView cnTv,enTv;
	}


}
